package com.yuexunit.operationman.nbsy.module.AfterOperation.ui;

import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.base.SubmitBean;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.AfterOperation.bean.AfterOperationBean;
import com.yuexunit.operationman.nbsy.module.AfterOperation.model.impl.AfterOperationModel;
import com.yuexunit.operationman.nbsy.module.AfterOperation.presenter.IAfterOperationPresenter;
import com.yuexunit.operationman.nbsy.module.AfterOperation.presenter.impl.AfterOperationPresenter;
import com.yuexunit.operationman.nbsy.module.AfterOperation.ui.view.IAfterOperationView;
import com.yuexunit.operationman.nbsy.module.SafeOperation.bean.SignBean;
import com.yuexunit.operationman.nbsy.module.SafeOperation.model.impl.SafeOperationSignModel;
import com.yuexunit.operationman.nbsy.module.SafeOperation.presenter.ISafeOperationSignPresenter;
import com.yuexunit.operationman.nbsy.module.SafeOperation.presenter.impl.SafeOperationSignPresenter;
import com.yuexunit.operationman.nbsy.module.SafeOperation.ui.view.ISafeOperationSignView;
import com.yuexunit.operationman.nbsy.widget.ActionSheetDialog;
import com.yuexunit.operationman.nbsy.widget.ClickDialog;
import com.yuexunit.operationman.nbsy.widget.CustomDatePicker;
import com.yuexunit.operationman.nbsy.widget.LoadingDialog;
import com.yuexunit.operationman.nbsy.widget.LoginDialog;

import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.PreferenceHelper;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by work-jx on 2017/3/1.
 */
public class Act_AfterOperation_Observeform extends BaseKJActivity implements IAfterOperationView, ISafeOperationSignView {
    @Bind(R.id.tv_patient_name)
    TextView tvPatientName;
    @Bind(R.id.tv_patient_sex)
    TextView tvPatientSex;
    @Bind(R.id.tv_patient_visitno)
    TextView tvPatientVisitno;
    @Bind(R.id.tv_patient_disease)
    TextView tvPatientDisease;
    @Bind(R.id.afteroperationmain_observeform_time_tv)
    TextView afteroperationmainObserveformTimeTv;
    @Bind(R.id.radio_01_01)
    RadioButton radio0101;
    @Bind(R.id.radio_01_02)
    RadioButton radio0102;
    @Bind(R.id.radio_02_01)
    RadioButton radio0201;
    @Bind(R.id.radio_02_02)
    RadioButton radio0202;
    @Bind(R.id.radio_03_01)
    RadioButton radio0301;
    @Bind(R.id.radio_03_02)
    RadioButton radio0302;
    @Bind(R.id.radio_04_01)
    RadioButton radio0401;
    @Bind(R.id.radio_04_02)
    RadioButton radio0402;
    @Bind(R.id.radio_05_01)
    RadioButton radio0501;
    @Bind(R.id.radio_05_02)
    RadioButton radio0502;
    @Bind(R.id.radio_061_01)
    RadioButton radio0601;
    @Bind(R.id.radio_06_02)
    RadioButton radio0602;
    @Bind(R.id.radio_07_01)
    RadioButton radio0701;
    @Bind(R.id.radio_07_02)
    RadioButton radio0702;
    @Bind(R.id.radio_08_01)
    RadioButton radio0801;
    @Bind(R.id.radio_08_02)
    RadioButton radio0802;
    @Bind(R.id.radio_09_01)
    RadioButton radio0901;
    @Bind(R.id.radio_09_02)
    RadioButton radio0902;
    @Bind(R.id.radio_10_01)
    RadioButton radio1001;
    @Bind(R.id.radio_10_02)
    RadioButton radio1002;

    //签名
    @Bind(R.id.img_ao_sign_01)
    ImageView imgAoSign01;
    @Bind(R.id.btn_ao_sign_01)
    TextView btnAoSign01;
    @Bind(R.id.tv_ao_sign_01_time)
    TextView tvAoSign01Time;
    @Bind(R.id.tv_ao_sign_01_name)
    TextView tvAoSign01Name;
    @Bind(R.id.img_ao_sign_name)
    TextView imgAoSignName;

    private CustomDatePicker customDatePicker1;
    private int type = -1;

    LoadingDialog loadingDialog;
    IAfterOperationPresenter presenter;

    LoginDialog loginDialog;
    ISafeOperationSignPresenter presenter_sign;

    AfterOperationBean.ObjectEntity.AoVisitObListEntity aoVisitObListEntity = new AfterOperationBean.ObjectEntity.AoVisitObListEntity();

    ClickDialog dialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_afteroperation_observeform);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        type = getIntent().getExtras().getInt("type");
        loginDialog = new LoginDialog(aty);
        loadingDialog = new LoadingDialog(this);
        presenter = new AfterOperationPresenter(this, new AfterOperationModel());
        presenter_sign = new SafeOperationSignPresenter(this, new SafeOperationSignModel());
        setTitle();
        setContent();
    }

    private void setTitle() {
        tvPatientName.setText(AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisit().getPatientName());
        if (AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisit().getPatientSex().equals("1")) {
            tvPatientSex.setText("男");
        } else if (AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisit().getPatientSex().equals("2")) {
            tvPatientSex.setText("女");
        } else {
            tvPatientSex.setText("不详");
        }
        tvPatientVisitno.setText("住院号" + AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisit().getInHospitalNo());
        tvPatientDisease.setText(PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_DISEASE));
    }

    private void setContent() {
        switch (type) {
            case 1:
                aoVisitObListEntity = AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(0);
                imgAoSignName.setText("观察医生(术后观察记录一)");
                if (AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(0).getObDoctorSignUrl() != null
                        && AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(0).getObDoctorSignUrl().length() > 0) {
                    imgAoSign01.setVisibility(View.VISIBLE);
                    btnAoSign01.setVisibility(View.GONE);
                    tvAoSign01Time.setVisibility(View.VISIBLE);
                    tvAoSign01Name.setVisibility(View.VISIBLE);
                    Glide.with(aty)
                            .load(AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(0).getObDoctorSignUrl())
                            .placeholder(R.color.white)
                            .error(R.color.white)
                            .into(imgAoSign01);
                    tvAoSign01Time.setText("签名时间:" + AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(0).getObDoctorSignTimeStr());
                    tvAoSign01Name.setText(AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(0).getObDoctorSign());
                }
                break;
            case 2:
                aoVisitObListEntity = AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(1);
                imgAoSignName.setText("观察医生(术后观察记录二)");
                if (AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(1).getObDoctorSignUrl() != null
                        && AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(1).getObDoctorSignUrl().length() > 0) {
                    imgAoSign01.setVisibility(View.VISIBLE);
                    btnAoSign01.setVisibility(View.GONE);
                    tvAoSign01Time.setVisibility(View.VISIBLE);
                    tvAoSign01Name.setVisibility(View.VISIBLE);
                    Glide.with(aty)
                            .load(AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(1).getObDoctorSignUrl())
                            .placeholder(R.color.white)
                            .error(R.color.white)
                            .into(imgAoSign01);
                    tvAoSign01Time.setText("签名时间:" + AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(1).getObDoctorSignTimeStr());
                    tvAoSign01Name.setText(AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(1).getObDoctorSign());
                }
                break;
        }
        if (aoVisitObListEntity.getAoVisitObId() != null) {

            if (aoVisitObListEntity.getObTimeStr() != null) {
                afteroperationmainObserveformTimeTv.setText(aoVisitObListEntity.getObTimeStr());
            }
            if (aoVisitObListEntity.getBreath() != null && aoVisitObListEntity.getBreath().length() > 0) {
                if (aoVisitObListEntity.getBreath().equals("1")) {
                    radio0101.setChecked(true);
                }
                if (aoVisitObListEntity.getBreath().equals("0")) {
                    radio0102.setChecked(true);
                }
            }
            if (aoVisitObListEntity.getTubes() != null && aoVisitObListEntity.getTubes().length() > 0) {
                if (aoVisitObListEntity.getTubes().equals("1")) {
                    radio0201.setChecked(true);
                }
                if (aoVisitObListEntity.getTubes().equals("0")) {
                    radio0202.setChecked(true);
                }
            }
            if (aoVisitObListEntity.getSteady() != null && aoVisitObListEntity.getSteady().length() > 0) {
                if (aoVisitObListEntity.getSteady().equals("1")) {
                    radio0301.setChecked(true);
                }
                if (aoVisitObListEntity.getSteady().equals("0")) {
                    radio0302.setChecked(true);
                }
            }
            if (aoVisitObListEntity.getSoreThroat() != null && aoVisitObListEntity.getSoreThroat().length() > 0) {
                if (aoVisitObListEntity.getSoreThroat().equals("1")) {
                    radio0901.setChecked(true);
                }
                if (aoVisitObListEntity.getSoreThroat().equals("0")) {
                    radio0902.setChecked(true);
                }
            }
            if (aoVisitObListEntity.getVomit() != null && aoVisitObListEntity.getVomit().length() > 0) {
                if (aoVisitObListEntity.getVomit().equals("1")) {
                    radio0401.setChecked(true);
                }
                if (aoVisitObListEntity.getVomit().equals("0")) {
                    radio0402.setChecked(true);
                }
            }
            if (aoVisitObListEntity.getSound() != null && aoVisitObListEntity.getSound().length() > 0) {
                if (aoVisitObListEntity.getSound().equals("1")) {
                    radio0501.setChecked(true);
                }
                if (aoVisitObListEntity.getSound().equals("0")) {
                    radio0502.setChecked(true);
                }
            }
            if (aoVisitObListEntity.getLowerBody() != null && aoVisitObListEntity.getLowerBody().length() > 0) {
                if (aoVisitObListEntity.getLowerBody().equals("1")) {
                    radio0601.setChecked(true);
                }
                if (aoVisitObListEntity.getLowerBody().equals("0")) {
                    radio0602.setChecked(true);
                }
            }
            if (aoVisitObListEntity.getBiopsy() != null && aoVisitObListEntity.getBiopsy().length() > 0) {
                if (aoVisitObListEntity.getBiopsy().equals("1")) {
                    radio0701.setChecked(true);
                }
                if (aoVisitObListEntity.getBiopsy().equals("0")) {
                    radio0702.setChecked(true);
                }
            }
            if (aoVisitObListEntity.getHeadache() != null && aoVisitObListEntity.getHeadache().length() > 0) {
                if (aoVisitObListEntity.getHeadache().equals("1")) {
                    radio0801.setChecked(true);
                }
                if (aoVisitObListEntity.getHeadache().equals("0")) {
                    radio0802.setChecked(true);
                }
            }
            if (aoVisitObListEntity.getUrinaryRetention() != null && aoVisitObListEntity.getUrinaryRetention().length() > 0) {
                if (aoVisitObListEntity.getUrinaryRetention().equals("1")) {
                    radio1001.setChecked(true);
                }
                if (aoVisitObListEntity.getUrinaryRetention().equals("0")) {
                    radio1002.setChecked(true);
                }
            }
        }
    }

    @OnClick({R.id.titlebar_docadvice_img_back, R.id.afteroperationmain_observeform_ll_01,
            R.id.radio_01_01, R.id.radio_01_02, R.id.radio_02_01, R.id.radio_02_02,
            R.id.radio_03_01, R.id.radio_03_02, R.id.radio_04_01, R.id.radio_04_02,
            R.id.radio_05_01, R.id.radio_05_02, R.id.radio_061_01, R.id.radio_06_02,
            R.id.radio_07_01, R.id.radio_07_02, R.id.radio_08_01, R.id.radio_08_02,
            R.id.radio_10_01, R.id.radio_10_02, R.id.afteroperationmain_observeform_btn
            , R.id.btn_ao_sign_01})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.titlebar_docadvice_img_back:
                finish();
                break;
            case R.id.afteroperationmain_observeform_ll_01:
                initDatePicker(afteroperationmainObserveformTimeTv);
                break;
            case R.id.radio_01_01:
                break;
            case R.id.radio_01_02:
                break;
            case R.id.radio_02_01:
                break;
            case R.id.radio_02_02:
                break;
            case R.id.radio_03_01:
                break;
            case R.id.radio_03_02:
                break;
            case R.id.radio_04_01:
                break;
            case R.id.radio_04_02:
                break;
            case R.id.radio_05_01:
                break;
            case R.id.radio_05_02:
                break;
            case R.id.radio_061_01:
                break;
            case R.id.radio_06_02:
                break;
            case R.id.radio_07_01:
                break;
            case R.id.radio_07_02:
                break;
            case R.id.radio_08_01:
                break;
            case R.id.radio_08_02:
                break;
            case R.id.radio_10_01:
                break;
            case R.id.radio_10_02:
                break;
            case R.id.afteroperationmain_observeform_btn:
                switch (type)
                {
                    case 1:
                        if( AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(0).getObDoctorSign()!=null&&
                        AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(0).getObDoctorSign().length()>0) {
                            insertContent();
                        }
                        else {
                            dialog = new ClickDialog(aty).builder().setTxt("存在未签名,是否提交？");
                            dialog.isCancleBack(true);
                            dialog.setCallBack(new ClickDialog.ICallBack() {
                                @Override
                                public void callback(Bundle bundle) {
                                    if(bundle.getInt("data") == 0){
                                        insertContent();
                                    } else if(bundle.getInt("data") == 1){
                                        dialog.dismiss();
                                    }

                                }
                            });
                            dialog.show();
                        }
                        break;
                    case 2:
                        if( AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(1).getObDoctorSign()!=null&&
                                AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(1).getObDoctorSign().length()>0) {
                            insertContent();
                        }
                        else {
                            dialog = new ClickDialog(aty).builder().setTxt("存在未签名,是否提交？");
                            dialog.isCancleBack(true);
                            dialog.setCallBack(new ClickDialog.ICallBack() {
                                @Override
                                public void callback(Bundle bundle) {
                                    if(bundle.getInt("data") == 0){
                                        insertContent();
                                    } else if(bundle.getInt("data") == 1){
                                        dialog.dismiss();
                                    }

                                }
                            });
                            dialog.show();
                        }
                        break;
                }
                break;
            case R.id.btn_ao_sign_01:
                showTypeDialog();
                break;

        }
    }

    private void showTypeDialog() {
        ActionSheetDialog actionSheetDialog;
        actionSheetDialog = new ActionSheetDialog(this).builder()
                .setCancelable(true)
                .setCanceledOnTouchOutside(true);
        actionSheetDialog.addSheetItem("HIS签名", ActionSheetDialog.SheetItemColor.Blue,
                new ActionSheetDialog.OnSheetItemClickListener() {
                    @Override
                    public void onClick(int which) {
                        loginDialog.builder();
                        loginDialog.show();
                        loginDialog.setCallBack(new LoginDialog.ICallBack() {
                            @Override
                            public void callback(Bundle bundle) {
                                Map<String, String> params = new HashMap<>();
                                params.put("jobNum", bundle.getString("person_num"));
                                params.put("loginPwd", bundle.getString("person_psw"));
                                presenter_sign.getSignInfo(params);
                            }
                        });
                    }
                });
        actionSheetDialog.addSheetItem("虹膜签名(暂不可用)", ActionSheetDialog.SheetItemColor.Blue,
                new ActionSheetDialog.OnSheetItemClickListener() {
                    @Override
                    public void onClick(int which) {

                    }
                });
        actionSheetDialog.show();
    }

    @Override
    public void getSignInfo(SignBean signBean) {
        loginDialog.dismiss();
        if (signBean.getCode() == 200) {
            if (signBean.getObject().getDoctorType().equals("Y")) {
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", java.util.Locale.getDefault());
                Date curDate = new Date(System.currentTimeMillis());//获取当前时间
                String str = formatter.format(curDate);
                switch (type) {
                    case 1:
                        imgAoSign01.setVisibility(View.VISIBLE);
                        Glide.with(this)
                                .load(signBean.getObject().getSignPicture())
                                .placeholder(R.color.white)
                                .error(R.color.white)
                                .into(imgAoSign01);
                        btnAoSign01.setVisibility(View.GONE);
                        tvAoSign01Time.setVisibility(View.VISIBLE);
                        tvAoSign01Time.setText("签名时间:" + str);
                        tvAoSign01Name.setVisibility(View.VISIBLE);
                        tvAoSign01Name.setText(signBean.getObject().getDoctorName());

                        AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(0).setObDoctorSign(signBean.getObject().getDoctorName());
                        AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(0).setObDoctorSignUrl(signBean.getObject().getSignPicture());
                        AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(0).setObDoctorSignTimeStr(str);
                        break;
                    case 2:
                        imgAoSign01.setVisibility(View.VISIBLE);
                        Glide.with(this)
                                .load(signBean.getObject().getSignPicture())
                                .placeholder(R.color.white)
                                .error(R.color.white)
                                .into(imgAoSign01);
                        btnAoSign01.setVisibility(View.GONE);
                        tvAoSign01Time.setVisibility(View.VISIBLE);
                        tvAoSign01Time.setText("签名时间:" + str);
                        tvAoSign01Name.setVisibility(View.VISIBLE);
                        tvAoSign01Name.setText(signBean.getObject().getDoctorName());

                        AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(1).setObDoctorSign(signBean.getObject().getDoctorName());
                        AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(1).setObDoctorSignUrl(signBean.getObject().getSignPicture());
                        AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().get(1).setObDoctorSignTimeStr(str);
                        break;
                }
            } else {
                ViewInject.toast("请使用医生账号进行签名");
            }
        } else {
            ViewInject.toast(signBean.getDesc());
        }
    }

    private void insertContent() {
        if (afteroperationmainObserveformTimeTv.getText().length() > 0) {
            aoVisitObListEntity.setObTimeStr(afteroperationmainObserveformTimeTv.getText().toString());
        }

        if (radio0101.isChecked()) {
            aoVisitObListEntity.setBreath("1");
        }
        if (radio0102.isChecked()) {
            aoVisitObListEntity.setBreath("0");
        }

        if (radio0201.isChecked()) {
            aoVisitObListEntity.setTubes("1");
        }
        if (radio0202.isChecked()) {
            aoVisitObListEntity.setTubes("0");
        }

        if (radio0301.isChecked()) {
            aoVisitObListEntity.setSteady("1");
        }
        if (radio0302.isChecked()) {
            aoVisitObListEntity.setSteady("0");
        }

        if (radio0901.isChecked()) {
            aoVisitObListEntity.setSoreThroat("1");
        }
        if (radio0902.isChecked()) {
            aoVisitObListEntity.setSoreThroat("0");
        }

        if (radio0401.isChecked()) {
            aoVisitObListEntity.setVomit("1");
        }
        if (radio0402.isChecked()) {
            aoVisitObListEntity.setVomit("0");
        }

        if (radio0501.isChecked()) {
            aoVisitObListEntity.setSound("1");
        }
        if (radio0502.isChecked()) {
            aoVisitObListEntity.setSound("0");
        }

        if (radio0601.isChecked()) {
            aoVisitObListEntity.setLowerBody("1");
        }
        if (radio0602.isChecked()) {
            aoVisitObListEntity.setLowerBody("0");
        }

        if (radio0701.isChecked()) {
            aoVisitObListEntity.setBiopsy("1");
        }
        if (radio0702.isChecked()) {
            aoVisitObListEntity.setBiopsy("0");
        }

        if (radio0801.isChecked()) {
            aoVisitObListEntity.setHeadache("1");
        }
        if (radio0802.isChecked()) {
            aoVisitObListEntity.setHeadache("0");
        }

        if (radio1001.isChecked()) {
            aoVisitObListEntity.setUrinaryRetention("1");
        }
        if (radio1002.isChecked()) {
            aoVisitObListEntity.setUrinaryRetention("0");
        }

        switch (type) {
            case 1:
                AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().set(0, aoVisitObListEntity);
                break;
            case 2:
                AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList().set(1, aoVisitObListEntity);
                break;
        }

        if (AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisit().getAoVisitId() == null) {
            Map<String, String> params = new HashMap<>();
            params.put("operationNo", PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_OPERATION_ID) + "");
            params.put("saveData", JSON.toJSONString(AppConfig.AFTEROPERATIONBEAN));
            presenter.insertAfterOperationDate(params);
        } else {
            Map<String, String> params = new HashMap<>();
            params.put("accountId", PreferenceHelper.readInt(aty, AppConfig.USER_INFO, AppConfig.USER_ACCOUNT) + "");
            params.put("fullName", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.USER_FULLNAME) + "");
            params.put("saveData", JSON.toJSONString(AppConfig.AFTEROPERATIONBEAN));
            presenter.updateAfterOperationDate(params);
        }
    }

    private void initDatePicker(final TextView view) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
        Date date1 = null;
        try {
            if (view.getText().toString().length() > 0) {
                date1 = sdf.parse(view.getText().toString());
            } else {
                date1 = new Date();
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String now = sdf.format(date1);

        CustomDatePicker customDatePicker1 = new CustomDatePicker(this, new CustomDatePicker.ResultHandler() {
            @Override
            public void handle(String time) { // 回调接口，获得选中的时间
                view.setText(time);
            }
        }, "2010-01-01 00:00", now); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
        customDatePicker1.showSpecificTime(true); // 显示时和分
        customDatePicker1.setIsLoop(true); // 循环滚动
        customDatePicker1.show(now);
    }

    @Override
    public void insertAfterOperationDate(SubmitBean submitBean) {
        if (submitBean.getCode() == 200) {
            ViewInject.toast("保存成功");
            finish();
        } else {
            ViewInject.toast(submitBean.getDesc());
        }
    }

    @Override
    public void updateAfterOperationDate(SubmitBean submitBean) {
        if (submitBean.getCode() == 200) {
            ViewInject.toast("保存成功");
            finish();
        } else {
            ViewInject.toast(submitBean.getDesc());
        }
    }

    @Override
    public void loadingDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                loadingDialog.setCanceledOnTouchOutside(false);
                loadingDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                loadingDialog.dismiss();
                break;

        }
    }

    /**
     * 通过dispatchTouchEvent每次ACTION_DOWN事件中动态判断非EditText本身区域的点击事件，然后在事件中进行屏蔽。然后当点击不是EditText时候，进行隐藏键盘操作
     *
     * @param ev
     * @return
     */

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            View v = getCurrentFocus();
            if (isShouldHideInput(v, ev)) {

                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null) {
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }
            }
            return super.dispatchTouchEvent(ev);
        }
        if (getWindow().superDispatchTouchEvent(ev)) {
            return true;
        }
        return onTouchEvent(ev);
    }

    public boolean isShouldHideInput(View v, MotionEvent event) {

        if (v != null && (v instanceof EditText)) {
            int[] leftTop = {0, 0};
            //获取输入框当前的location位置
            v.getLocationInWindow(leftTop);
            int left = leftTop[0];
            int top = leftTop[1];
            int bottom = top + v.getHeight();
            int right = left + v.getWidth();
            if (event.getX() > left && event.getX() < right
                    && event.getY() > top && event.getY() < bottom) {
                // 点击的是输入框区域，保留点击EditText的事件\
                return false;
            } else {
                return true;
            }
        }
        return false;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
